/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.service.impl;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.lang.domain.Result;
import com.xy.biz.fd.domain.bo.DocumentAttachmentBO;
import com.xy.biz.fd.domain.query.DocumentAttachmentQuery;
import com.xy.biz.fd.service.DocumentAttachmentService;
import com.xy.biz.fd.manager.DocumentAttachmentManager;

/**
 *
 *
 * @author wcs
 * @date 2021-2-19
 */
@Service
public class DocumentAttachmentServiceImpl implements DocumentAttachmentService {

	@Autowired
	private DocumentAttachmentManager documentAttachmentManager;

	@Override
	public Result<?> saveDocumentAttachment(DocumentAttachmentBO documentAttachmentBO) {
		documentAttachmentBO.setCreateTime(LocalDateTime.now());
		documentAttachmentBO.setUpdateTime(LocalDateTime.now());
		documentAttachmentBO.setDeleteFlag(false);
		int affectedRows = documentAttachmentManager.saveDocumentAttachment(documentAttachmentBO);
		if (affectedRows > 0) {
			return Result.success();
		}
		return Result.ofErrorRowsAffected();
	}

	@Override
	public Result<?> saveAllDocumentAttachment(Collection<DocumentAttachmentBO> collection) {
		int affectedRows = documentAttachmentManager.saveAllDocumentAttachment(collection);
		if (affectedRows > 0) {
			return Result.success();
		}
		return Result.ofErrorRowsAffected();
	}

	@Override
	public Result<?> updateDocumentAttachment(DocumentAttachmentBO documentAttachmentBO) {
		int affectedRows = documentAttachmentManager.updateDocumentAttachment(documentAttachmentBO);
		if (affectedRows > 0) {
			return Result.success();
		}
		return Result.ofErrorRowsAffected();
	}

	@Override
	public Result<?> deleteDocumentAttachment(Long documentAttachmentId) {
		int affectedRows = documentAttachmentManager.deleteDocumentAttachment(documentAttachmentId);
		if (affectedRows > 0) {
			return Result.success();
		}
		return Result.ofErrorRowsAffected();
	}

	@Override
	public DocumentAttachmentBO getDocumentAttachment(Long documentAttachmentId) {
		return documentAttachmentManager.getDocumentAttachment(documentAttachmentId);
	}

	@Override
	public List<DocumentAttachmentBO> listDocumentAttachmentById(Collection<Long> collection) {
		return documentAttachmentManager.listDocumentAttachmentById(collection);
	}

	@Override
	public List<DocumentAttachmentBO> listDocumentAttachment(DocumentAttachmentQuery query) {
		return documentAttachmentManager.listDocumentAttachment(query);
	}

	@Override
	public int countDocumentAttachment(DocumentAttachmentQuery query) {
		return documentAttachmentManager.countDocumentAttachment(query);
	}

}
